package com.wonyesoft.wuliu.acticity.baidumap;

import javabeen.DriverAddress;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Gravity;
import android.widget.TextView;

import com.baidu.mapapi.map.BaiduMap;
import com.baidu.mapapi.map.BaiduMapOptions;
import com.baidu.mapapi.map.BitmapDescriptor;
import com.baidu.mapapi.map.BitmapDescriptorFactory;
import com.baidu.mapapi.map.MapStatus;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.map.MarkerOptions;
import com.baidu.mapapi.map.OverlayOptions;
import com.baidu.mapapi.model.LatLng;
import com.wonyesoft.wuliu.AppContent;
import com.wonyesoft.wuliu.R;
import com.wonyesoft.wuliu.acticity.base.BaseActivity;

/**
 * * @author 作者 陈修园E-mail: * 
 * @date 创建时间：2015-7-11 下午7:28:19 * 
 * @version 1.0 * @parameter
 * * @since * @return
 */
public class ShowDriverInMap extends BaseActivity {
	private MapView mMapView;
	private BaiduMap mBaiduMap;
	private LatLng point;
	private LatLng userPoint;
	private DriverAddress driverInfo;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		Intent intent=getIntent();
		driverInfo=(DriverAddress) intent.getSerializableExtra("driverInfo");
		AppContent app=(AppContent) getApplication();
		userPoint=new LatLng(app.latitude, app.longitude);
		Log.v("userPoint", userPoint.toString());
		if (driverInfo!=null) {
			
			point=new LatLng(Double.parseDouble(driverInfo.getLatitude()), Double.parseDouble(driverInfo.getLongitude()));

			mMapView = new MapView(this,new BaiduMapOptions().mapStatus(new MapStatus.Builder()
							.target(point).zoom(16).build()));
		Log.v("point", point.toString());
		
		}else {
			mMapView = new MapView(this, new BaiduMapOptions());
		}
//		mMapView.setZoomControlsPosition(arg0);
		setContentView(mMapView);
		mBaiduMap = mMapView.getMap();
		
		iniMap();
	}
	
	
	private void iniMap(){
		TextView driver_teTextView=new TextView(this);
		String driveraddress=driverInfo.getLicenseplate();
		int strLean = driveraddress.length();
//		if (strLean > 3) {
//			driveraddress = driveraddress.substring(0, strLean - 3) + "**"+ driveraddress.substring(strLean - 1,strLean);
//		}
		driver_teTextView.setTextSize(11);
		driver_teTextView.setText(driverInfo.getCarownername()+'\n'+driveraddress);
		driver_teTextView.setGravity(Gravity.CENTER);
		driver_teTextView.setBackgroundResource(R.drawable.popup);
		BitmapDescriptor bitmap=new BitmapDescriptorFactory().fromView(driver_teTextView);
		BitmapDescriptor bitmapDescriptor=new BitmapDescriptorFactory().fromResource(R.drawable.myplase);
		OverlayOptions driver=new MarkerOptions().position(point).icon(bitmap).title(driverInfo.getCarownername());
		OverlayOptions user_option=new MarkerOptions().position(userPoint).icon(bitmapDescriptor).title("我的位置");
	
		mBaiduMap.addOverlay(driver);
	//	mBaiduMap.addOverlay(user_option);
	}
	
	
	@Override
	protected void onPause() {
		super.onPause();
		mMapView.onPause();
	}

	@Override
	protected void onResume() {
		super.onResume();
		mMapView.onResume();
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		mMapView.onDestroy();
	}

	
	
}
